<template>
  <view class="ai-card" @tap="onClick">
    <view class="ai-card__avatar">
      <image :src="props.avatar" mode="aspectFill"/>
    </view>
    <view class="ai-card__content">
      <view class="ai-card__title text-ellipsis">{{props.name}}</view>
      <view class="ai-card__desc text-ellipsis-2">{{props.description}}</view>
      <view class="ai-card__info">
        <text>{{props.chatCount}}人聊过</text>
        <view class="collect" @tap.stop="onCollect">
          <text :class="['iconfont', isCollected ? 'icon-star-filled' : 'icon-star']"/>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
const props = defineProps({
  id: Number,
  avatar: String,
  name: String, 
  description: String,
  chatCount: Number,
  isCollected: Boolean
})

const emit = defineEmits(['click', 'collect'])

const onClick = () => {
  emit('click', props.id)
}

const onCollect = () => {
  emit('collect', props.id)
}
</script>

<style lang="scss">
.ai-card {
  display: flex;
  padding: 20rpx;
  background: #fff;
  border-radius: 12rpx;
  margin-bottom: 20rpx;
  
  &__avatar {
    width: 100rpx;
    height: 100rpx;
    margin-right: 20rpx;
    flex-shrink: 0; // 防止头像被压缩
    
    image {
      width: 100%;
      height: 100%;
      border-radius: 12rpx;
    }
  }
  
  &__content {
      flex: 1;
      min-width: 0; // 允许内容区域收缩
      
      .ai-card__title {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      
      .ai-card__desc {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  
  &__title {
    font-size: 32rpx;
    font-weight: 500;
    margin-bottom: 8rpx;
  }
  
  &__desc {
    font-size: 28rpx;
    color: #666;
    margin-bottom: 16rpx;
    line-height: 1.4;
  }
  
  &__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 26rpx;
    color: #999;
    
    .collect {
      font-size: 36rpx;
      color: #FFB800;
    }
  }
}

// 文字溢出处理的通用样式
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-ellipsis-2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}
</style>